﻿package com.xeem.henkel.common
{
	import fl.motion.MatrixTransformer;
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	
	public class Clock extends MovieClip
	{

		public var barClk:MovieClip;  
		
		public var data:DataModel;
		
		private var tt:Sprite=new Sprite;
		
		private var old:Number=0;
		
		private var m:Matrix;
		
		public function Clock()
		{
			var bgClk:MovieClip=new bgClock();
			barClk=new barClock();
			addChild(bgClk);			
			addChild(barClk);
			barClk.x=50.6;
			barClk.y=49.5;
			m = barClk.transform.matrix;
			MatrixTransformer.rotateAroundExternalPoint(m,50.6,49.5,120);//
			barClk.transform.matrix=m;
			addChild(tt);			
		}
		
	
		public function drawData(d:Number):void
		{
			var dd:Number=d*300/data.rangeData;
			trace(dd);
			m = barClk.transform.matrix;
			MatrixTransformer.rotateAroundExternalPoint(m,50.6,49.5,dd-old);//
			barClk.transform.matrix=m;
			old=dd;
			tt.graphics.clear();
			DrawSector(tt,50.6,49.5,35,dd,120);
			//_btn.addEventListener(MouseEvent.MOUSE_OUT,onStopDragHandler);   
		} 
		
		private function DrawSector(sprite:Sprite,x:Number=200,y:Number=200,r:Number=100,angle:Number=27,startFrom:Number=270,color:Number=0x008CD6):void {
			sprite.graphics.beginFill(color,0.3);
			sprite.graphics.lineStyle(1,color);
			sprite.graphics.moveTo(x,y);
			angle=(Math.abs(angle)>360)?360:angle;
			var n:Number=Math.ceil(Math.abs(angle)/45);
			var angleA:Number=angle/n;
			angleA=angleA*Math.PI/180;
			startFrom=startFrom*Math.PI/180;
			sprite.graphics.lineTo(x+r*Math.cos(startFrom),y+r*Math.sin(startFrom));
			for (var i=1; i<=n; i++) {
				startFrom+=angleA;
				var angleMid=startFrom-angleA/2;
				var bx=x+r/Math.cos(angleA/2)*Math.cos(angleMid);
				var by=y+r/Math.cos(angleA/2)*Math.sin(angleMid);
				var cx=x+r*Math.cos(startFrom);
				var cy=y+r*Math.sin(startFrom);
				sprite.graphics.curveTo(bx,by,cx,cy);
			}
			if (angle!=360) {
				sprite.graphics.lineTo(x,y);
			}
			sprite.graphics.endFill();
			
		}

	}
}